<!DOCTYPE html>
<html>
<head>
<title>Physics Diagram of a Proton and an Electric Field</title>
</head>
<body>
<canvas id="physicsCanvas" width="500" height="350" style="border:1px solid #000;"></canvas>
<script>
    const canvas = document.getElementById('physicsCanvas');
    const ctx = canvas.getContext('2d');

    // Helper function to draw an arrow
    function drawArrow(ctx, fromx, fromy, tox, toy, arrowWidth, color) {
        const headlen = 10;
        const dx = tox - fromx;
        const dy = toy - fromy;
        const angle = Math.atan2(dy, dx);

        ctx.save();
        ctx.strokeStyle = color;
        ctx.fillStyle = color;
        ctx.lineWidth = 2;

        // Line
        ctx.beginPath();
        ctx.moveTo(fromx, fromy);
        ctx.lineTo(tox, toy);
        ctx.stroke();

        // Arrowhead
        ctx.beginPath();
        ctx.moveTo(tox, toy);
        ctx.lineTo(tox - headlen * Math.cos(angle - Math.PI / 7), toy - headlen * Math.sin(angle - Math.PI / 7));
        ctx.lineTo(tox - headlen * Math.cos(angle + Math.PI / 7), toy - headlen * Math.sin(angle + Math.PI / 7));
        ctx.closePath();
        ctx.fill();
        ctx.restore();
    }

    // Set drawing parameters
    const centerX = 320;
    const centerY = 175;
    const mainRadius = 120;
    const protonX = 120;
    const protonY = 175;
    const particleRadius = 5;
    const dotRadius = 4;

    // Draw the circular region
    ctx.beginPath();
    ctx.arc(centerX, centerY, mainRadius, 0, 2 * Math.PI);
    ctx.lineWidth = 2;
    ctx.strokeStyle = 'black';
    ctx.stroke();

    // Draw the electric field representation (dots)
    ctx.fillStyle = 'black';
    // Center dot
    ctx.beginPath();
    ctx.arc(centerX, centerY, dotRadius, 0, 2 * Math.PI);
    ctx.fill();

    // Outer dots in a hexagonal pattern
    const innerRadius = mainRadius * 0.65;
    for (let i = 0; i < 6; i++) {
        const angle = (i * 60 + 30) * Math.PI / 180; // Rotated by 30 degrees
        const x = centerX + innerRadius * Math.cos(angle);
        const y = centerY + innerRadius * Math.sin(angle);
        ctx.beginPath();
        ctx.arc(x, y, dotRadius, 0, 2 * Math.PI);
        ctx.fill();
    }

    // Draw the radius line 'R'
    const radiusAngle = -35 * Math.PI / 180;
    const radiusEndX = centerX + mainRadius * Math.cos(radiusAngle);
    const radiusEndY = centerY + mainRadius * Math.sin(radiusAngle);
    ctx.beginPath();
    ctx.moveTo(centerX, centerY);
    ctx.lineTo(radiusEndX, radiusEndY);
    ctx.stroke();

    // Draw labels 'E' and 'R'
    ctx.font = "bold 30px serif";
    ctx.fillText("E", centerX - 80, centerY - 50);
    ctx.fillText("R", centerX + 50, centerY + 50);

    // Draw the proton
    ctx.beginPath();
    ctx.arc(protonX, protonY, particleRadius, 0, 2 * Math.PI);
    ctx.fill();

    // Draw the proton label 'p+'
    ctx.font = "bold 30px serif";
    ctx.fillText("p", protonX - 10, protonY - 15);
    ctx.font = "bold 20px serif";
    ctx.fillText("+", protonX + 8, protonY - 22);

    // Draw the velocity vector 'v'
    const arrowStartX = protonX + 10;
    const arrowLength = 70;
    drawArrow(ctx, arrowStartX, protonY, arrowStartX + arrowLength, protonY, 10, 'black');
    
    // Draw the velocity label 'v'
    ctx.font = "bold 30px serif";
    ctx.fillText("v", protonX + 35, protonY + 30);

</script>
</body>
</html>